package cn.xxxy.fourm.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import cn.xxxy.fourm.dao.BoardDao;
import cn.xxxy.fourm.entity.Board;
import cn.xxxy.fourm.model.BoardDto;
import cn.xxxy.fourm.service.BoardService;

@Service@Transactional
public class BoardServiceImpl implements BoardService{
	@Autowired
	private BoardDao boardDao;
	@Override
	public List<BoardDto> listPage(int page, int rows) {
		Pageable pageable = new PageRequest(page-1,rows);
		Page<Board> list=boardDao.findAll(pageable);
		List<BoardDto> listDto=new ArrayList<>();
		for (Board board : list) {
			BoardDto boardDto=new BoardDto();
			boardDto.setBid(board.getBid());
			boardDto.setBname(board.getBname());
			boardDto.setId(board.getBoardState().getId());
			boardDto.setBoardState(board.getBoardState().getBname());
			listDto.add(boardDto);
		}
		return listDto;
	}

}
